package com.capgemini.cn.authority.data.repository;

import com.capgemini.cn.authority.data.entity.AssertsGroup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.List;

/**
 * Created at 2017/8/24
 *
 * @author Andriy
 */
@Repository
public interface AssertsGroupRepository extends JpaRepository<AssertsGroup, Long> {

    /**
     * 根据资源组名查询资源组信息 - <span style='color:yellow'>使用悲观写锁控制数据脏读</span>
     *
     * @param assertsGroupName 资源组名称
     */
    @Lock(value = LockModeType.PESSIMISTIC_WRITE)
    AssertsGroup findByAssertsGroupNameEquals(@Param(value = "assertsGroupName") String assertsGroupName);

    /**
     * 根据是否系统自动创建的状态查找所有资源组
     *
     * @param systemCreated 是否系统自动创建
     */
    List<AssertsGroup> findAllBySystemCreated(@Param(value = "systemCreated") boolean systemCreated);
}
